package com.fhz.circle.welcome;

import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.fhz.circle.MainActivity;
import com.fhz.circle.R;
import com.fhz.circle.welcome.adapter.WelcomeAdapter;
import com.fhz.circle.welcome.fragment.WelcomeFragmentOne;
import com.fhz.circle.welcome.fragment.WelcomeFragmentTwo;
import com.fhz.circle.widget.CountDownView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author: fhz
 * @describe: 欢迎界面
 * @date: 2021-11-11 21:23:06
 * <p>
 * 解决的问题:
 * 1 第一次登录是欢迎页面
 * 2 第二次登录是主页面
 * 3 版本更新后,又是欢迎页面
 * 4 如果是强登录页面, 如微信之类的要求必须先登录的,那么就要跳转到登录页面 (token)
 * 5 登录的信息要记录. 用户一次登录,长时间有效.
 * 6 适配刘海屏  清单文件 android:resizeableActivity="true" 版本大于26
 * <p>
 * 7 自定义view的圆形倒计时
 */

public class WelcomeActivity extends AppCompatActivity {

    @BindView(R.id.welcome_viewpager)
    ViewPager welcomeViewpager;
    @BindView(R.id.welcome_circle_one)
    ImageView welcomeCircleOne;
    @BindView(R.id.welcome_circle_two)
    ImageView welcomeCircleTwo;
    @BindView(R.id.countDownView)
    CountDownView countDownView;

    private List<Fragment> list;
    private static final String TAG = "WelcomeActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        list = new ArrayList<>();
        list.add(new WelcomeFragmentOne());
        list.add(new WelcomeFragmentTwo());

        //倒计时
        countDownView.start(this);
        countDownView.setMyListener(() -> {
            MainActivity.launch(this);
            finish();
        });


        WelcomeAdapter welcomeAdapter = new WelcomeAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, list);
        welcomeViewpager.setAdapter(welcomeAdapter);

        welcomeViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        welcomeCircleOne.setImageResource(R.drawable.img_guide_point_p);
                        welcomeCircleTwo.setImageResource(R.drawable.img_guide_point);
                        break;
                    case 1:
                        welcomeCircleOne.setImageResource(R.drawable.img_guide_point);
                        welcomeCircleTwo.setImageResource(R.drawable.img_guide_point_p);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
